<div class="breadcrumb">
    <ul id="breadcrumb">
        <li><a href="<?php echo Configure::read('base_url'); ?>backstage" title="Home">
                <?php echo $this->Html->image("home.png", array("alt" => "Home", 'class' => 'home', 'border' => '0')); ?>
            </a></li>
        <li><a href="<?php echo Configure::read('base_url'); ?>backstage/users/seller" title="Manage Seller">Manage Seller</a></li>

    </ul>
</div>
<?php echo $this->element('admin/admin_leftmenu'); ?>
                <div id="left">
    <?php
                echo $this->Session->flash();
                if ($this->Session->check('Message.auth'))
                    echo $this->Session->flash('auth');
    ?>
                <div class="div_header"><?php __('Manage Seller'); ?></div>
                <div class="div_content">
                    <form method="post" id="suspendfrm" action="<?php echo Configure::read('base_url')."backstage/users/sellersearch/"; ?>">
<table width="70%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="144"  style="border:0px;">
Search a seller by:&nbsp;&nbsp;<input type="text" size="28" title="Enter seller here" onblur="if(this.value==''){this.value='Enter Seller ID / Name or Email'}" onfocus="if(this.value=='Enter Seller ID / Name or Email'){this.value=''}" value="Enter Seller ID / Name or Email" name="data[searchkey]">
&nbsp;&nbsp;<select name="data[type]">
    <option value="">select</option>
    <option value="id">Seller id</option>
    <option value="name">Name</option>
    <option value="email">E-mail</option>
</select>&nbsp;&nbsp;<input type="submit" style="background:#73AE0B;
color:#fff; font-size:14px;" name="button" id="button" value="Search" />
</td>
</tr>
</table>
            
</form>
                    <table id="category_table" cellspacing="0" class="tablesorter">
                        <thead>
                            <tr>
            <!--                    <th width="50" ><?php //echo _('id');  ?></th>-->
                                <th width="100" ><?php echo _('Username'); ?></th>
                                <th width="120" ><?php echo _('Name'); ?></th>
                                <th width="110" ><?php echo _('Email'); ?></th>
                                <th width="42" ><?php echo _('Feedback'); ?></th>
                                <th width="120" ><?php echo _('Date of Registration'); ?></th>
                                <th width="50" ><?php echo _('Level'); ?></th>
                                <th width="84" >Actions</th>

                            </tr>
                        </thead>
                        <tbody>
                <?php
                $i = 0;
               if(!empty($users)){
                foreach ($users as $user):
                    $class = null;
                    if ($i++ % 2 == 0) :
                        $class = ' class="alt"';
                ?>
                        <tr>
        <!--                            <td class="alt"><?php //echo $i;  ?></td>-->
 <td class="alt"><a href="javascript:void(0);" controller="users" action="seller_account"
  title="Edit" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>
                            <?php echo $user['User']['username']; ?></a></td>
                    <td class="alt"><a href="javascript:void(0);" controller="users" action="seller_account"
  title="Edit" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>
                            <?php echo $user['User']['first_name'];
                            echo' ';
                            echo $user['User']['last_name']; ?></a>
                    </td>
                    <td class="alt"><?php echo $user['User']['email']; ?></td>
                    <td class="alt"><a href="javascript:void(0);"  controller="users" action="feedback"
  title="feedback" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>View</a>&nbsp;</td>
                    <td class="alt"><?php echo date('d-m-Y', strtotime($user['User']['created'])); ?></td>
                    <td class="alt">
                    <?php echo $this->Form->input('User.group_id', array('div' => false, 'label' => false,'id' => 'UserGroupId'.$user['User']['id'], 'selected' => $user['User']['group_id'], 'onchange' => 'change_level("' . $user['User']['id'] . '")')); ?>
                        
                    </td>
                    <td align="center" class="alt">
                        <?php echo $html->link('Contact Seller',array('backstage' => true, 'controller' => 'messages', 'action' => 'new_message',$user['User']['id']), array()); ?>&nbsp;&nbsp;
                         <?php
                    if($user['User']['active']==1){
                    ?>
                       <a href="javascript:void(0);" controller="users" action="suspend"
                           title="Suspend" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>
                        Suspend
                        </a>
                                <?php
                                }else{
                                ?>
                  <a href="javascript:void(0);" controller="users" action="reactive"
                           title="Reactive" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>
                        Re-activate
                        </a>
                                <?php
                                }
                                ?>
                        </td>

                    </tr>
<?php else: ?>
                                <tr>
                <!--                                  <td><?php //echo $i; ?></td>-->
                        <td><a href="javascript:void(0);" controller="users" action="seller_account"
  title="Edit" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>
                            <?php echo $user['User']['username']; ?></a></td>
                        <td><a href="javascript:void(0);" controller="users" action="seller_account"
  title="Edit" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>
<?php echo $user['User']['first_name'];
                                echo' ';
                                echo $user['User']['last_name']; ?></a>
                        </td>
                        <td><?php echo $user['User']['email']; ?></td>
                            <td ><a href="javascript:void(0);"  controller="users" action="feedback"
  title="feedback" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>View</a>&nbsp;</td>
                            <td ><?php
                                //echo $user['User']['created'];
                                echo date('d-m-Y', strtotime($user['User']['created']));
?></td>
                            <td ><?php 
                            echo $this->Form->input('User.group_id', array('div' => false, 'label' => false, 'selected' => $user['User']['group_id'],'id' => 'UserGroupId'.$user['User']['id'], 'onchange' => 'change_level("' . $user['User']['id'] . '")')); ?>
                            
                            </td>
                            <td align="center" >
                                <?php echo $html->link('Contact Seller',array('backstage' => true, 'controller' => 'messages', 'action' => 'new_message',$user['User']['id']), array()); ?>&nbsp;&nbsp;
                    <?php
                    if($user['User']['active']==1){
                    ?>
                       <a href="javascript:void(0);" controller="users" action="suspend"
                           title="Suspend" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>
                        Suspend
                        </a>
                                <?php
                                }else{
                                ?>
                  <a href="javascript:void(0);" controller="users" action="reactive"
                           title="Reactive" ElmID="<?php echo $user['User']['id']; ?>" onclick='showPop(this)'>
                        Re-activate
                        </a>
                                <?php
                                }
                                ?>
                            </td>

                                </tr>
                        <?php endif;
                            endforeach;
                            }else{
                            ?>
                                <tr><td colspan="7">No Seller found!</td></tr>
                            <?php
                            }
                            ?>
                            <tbody>
                        </table>
                        <div class="paging">
<?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class' => 'disabled')); ?>
                	 | 	<?php echo $this->Paginator->numbers(); ?>
                            |
<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled')); ?>
                        </div>
                    </div>
                    <div class="div_bottom"></div>
                </div>

                <!-- edit sidebar items here -->

                </div>

<?php echo $html->script(array("jquery.pagination.js", "jquery.tablesorter.min.js", "jquery.tablednd.js")); ?>
                            <script type="text/javascript">

                                jQuery(document).ready(function(){
                                    jQuery("#category_table").tablesorter({headers: {3:{sorter: false},5:{sorter: false}, 6:{sorter: false}}});
                                });

                                function change_level(id){
                                    var lid=jQuery("#UserGroupId"+id).val();
                                    //alert(lid);
                                   // die();
                                    var r=confirm("Do you really want to change the level of the Seller?");
                                    if (r){
                                        jQuery.ajax({
                                            url : "<?php echo Configure::read('base_url'); ?>users/changelevel/"+id+'/'+lid,
                                    success : function (html) {
                                        //document.getElementById("status"+id).innerHTML = "";
                                        //jQuery("#UserGroupId"+id).append('success');
                                               }
                                        });
                                    }else{
                                   window.location.assign("<?php echo Configure::read('base_url'); ?>backstage/users/seller/")
                                    }
                                    //alert(jQuery("#UserGroupId").val());
                                }
</script>